﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta><style>/*<![CDATA[*/

table{border: 1px solid gray;}
td{border: 1px dotted gray;}
p{margin: 3px 0 3px 0; padding: 0;}
#ID_Footer{font-size: small; font-style: italic; text-align: right; margin-top: 4em; padding-top: 4px; border-top: 2px solid gray;}

/*]]>*/</style><title>23. 24. ThinkPHP 3.1.2 URL 1 2</title></head><body>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 14pt; font-weight: bold; line-height: 140%">本节课大纲：</span></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 12pt; font-weight: bold; line-height: 190%">一、URL规则</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp;1、默认是区分大小写的 </span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;2、如果我们不想区分大小写可以改配置文件</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 190%">URL_CASE_INSENSITIVE</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">&apos;=&gt;true,//url不区分大小写 &nbsp; &nbsp; &nbsp; &nbsp;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;3、如果模块名为 </span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">UserGroupAction</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;那么url找模块就必要要写成: </span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">user_group</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><a href="http://localhost/thinkphp4/index.php/user_group/index" style="font-family: 微软雅黑; font-size: 10pt; text-decoration: underline; color: #0000ff">http://localhost/thinkphp4/index.php/user_group/index</a></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;4、如果</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">&apos;URL_CASE_INSENSITIVE&apos;=&gt;false</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;那么url也可以写为(user_group好像也可以)</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><a href="http://localhost/thinkphp4/index.php/UserGroup/index" style="font-family: 微软雅黑; font-size: 10pt; text-decoration: underline; color: #0000ff">http://localhost/thinkphp4/index.php/UserGroup/index</a></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 12pt; font-weight: bold; line-height: 190%">二、URL伪静态</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp;默认设置了伪静态：可以使用.html, .pdf, .xml</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">URL_HTML_SUFFIX</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">&apos;=&gt;&apos;html|shtml|xml&apos;,//限制伪静态的后缀</span></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 12pt; font-weight: bold; line-height: 190%">三、URL路由</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;使得可以用其它方式访问URL</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp;必须为pathinfo方式</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;1、启动路由</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要在配置文件中开启路由支持</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 240%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 240%">URL_ROUTE_ON</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 240%">&apos;=&gt;true,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;2、使用路由</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 190%">URL_ROUTE_RULES</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">&apos; =&gt; array( &nbsp;),  &nbsp; &nbsp; &nbsp; &nbsp;//定义路由规则</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a. </span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">规则表达式配置</span><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">路由</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my&apos;=&gt;&apos;Index/index&apos;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 190%">静态地址路由</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">, 使用my就可以访问Index模块下的index方法</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;:id/:num&apos;=&gt;&apos;Index/index&apos;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 190%">动态地址路由</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">， 这样可以用100/1000访问，用于get传参, $_GET[&apos;num&apos;], $_GET[&apos;id&apos;];</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:num&apos;=&gt;&apos;Index/index&apos;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 140%">混合地址路由</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">, 可以用my/abc, $_GET[&apos;num&apos;]传值为&apos;abc&apos;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;year/:year/:month/:date&apos;=&gt;&apos;Index/index&apos;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//动态和静态混合地址路由, echo &quot;{year: $_GET[&apos;year&apos;] }, {month: $_GET[&apos;month&apos;]}, {date: $_GET[&apos;date&apos;]}&quot;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;加上</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%"> \d</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">代表类型只能是数字（目前thinkphp只支持数字检测）</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;year/:year</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 190%">\d</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">/:month</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 190%">\d</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">/:date</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 190%">\d&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">=&gt;&apos;Index/index&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:id$&apos;=&gt;&apos;Index/index&apos;,// 加上</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 190%">$</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 190%">说明地址中只能是 my/1000 后面不能有其他内容了</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b. </span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">正则表达式配置</span><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">路由</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;以/开始，以/结束</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;转义符：\, 如\/</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\d{4}，数字出现4次</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;：1，第一部分，即\d{4}代替:1，此时须用括号括起</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^year, 以year开始</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;/^year\/(\d{4})\/(\d{2})\/(\d{2})/&apos;=&gt;&apos;Index/index</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">?</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">year=</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">:1</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">&amp;month=</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">:2</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">&amp;date=</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">:3</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">&apos;</span></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;3、注意事项：</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a. &nbsp;越复杂的路由越往前面放</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;URL_ROUTE_RULES&apos;=&gt;array(</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:year/:month:/:day&apos;=&gt;&apos;Index/day&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:id\d&apos;=&gt;&apos;Index/index&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:name&apos;=&gt;&apos;Index/index&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 190%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b. &nbsp;可以使用</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">$</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">作为</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #0000ff; line-height: 140%">完全匹配</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">的路由规则</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;URL_ROUTE_RULES&apos;=&gt;array(</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:id\d$&apos;=&gt;&apos;Index/index&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:name$&apos;=&gt;&apos;Index/index&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;my/:year/:month:/:day$&apos;=&gt;&apos;Index/day&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;),</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c. &nbsp;用正则匹配的方式</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;URL_ROUTE_RULES&apos;=&gt;array(</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;/^my\/(</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">\d+</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">)</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">$</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">/&apos;=&gt;&apos;Index/index?id=:1&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;/^my\/(</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">\w+</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">)</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">$</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">/&apos;=&gt;&apos;Index/index?name=:1&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&apos;/^my\/(\d{4})\/(\d{2})\/(\d{2})</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; color: #ff0000; line-height: 140%">$</span><span style="font-family: 微软雅黑; font-size: 10pt; color: #000000; line-height: 140%">/&apos;=&gt;&apos;Index/day?year=:1&amp;month=:2&amp;day=:3&apos;,</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;),</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 12pt; font-weight: bold; line-height: 190%">四、URL重写</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;rewrite重写，即可以省略index.php</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Apache的配置过程，可以参考下：</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1、httpd.conf配置文件中加载了mod_rewrite.so模块</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2、AllowOverride None 将None改为 All</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3、确保URL_MODEL设置为2 &nbsp; &nbsp; &nbsp; &nbsp;(可省）</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4、把下面的内容保存为.htaccess文件放到入口文件的同级目录下</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;IfModule mod_rewrite.c&gt;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RewriteEngine on</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RewriteCond %{REQUEST_FILENAME} !-d</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RewriteCond %{REQUEST_FILENAME} !-f</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/IfModule&gt;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 12pt; font-weight: bold; line-height: 140%">五、URL生成</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;U方法</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U(&apos;[分组/模块/操作]?参数&apos; [,&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">参数</span><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">&apos;,&apos;</span><span style="font-family: 微软雅黑; font-size: 10pt; font-weight: bold; line-height: 140%">伪静态后缀</span><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">&apos;,&apos;是否跳转&apos;,&apos;显示域名&apos;])</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U(Index/index) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//生成Index模块的index操作的URL地址</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U(&apos;Blog/read?id=1&apos;)  &nbsp; &nbsp; &nbsp; &nbsp;// 生成Blog模块的read操作 并且id为1的URL地址</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U(&apos;Blog/cate&apos;,array(&apos;cate_id&apos;=&gt;1,&apos;status&apos;=&gt;1)) &nbsp; &nbsp; &nbsp; &nbsp;//</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">++++++++++++++++++++++++++++++++++++Leo+++++++++++++++++++++++++++++++++</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">路径最前面的&quot;/&quot;</span></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%"> &nbsp; &nbsp; &nbsp; &nbsp;表明网站的根目录，即www目录:localhost</span></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 10pt; line-height: 140%">todo:最近几课均未实践</span></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div><script type="text/javascript" language="javascript" src="jquery.js"></script><script type="text/javascript" language="javascript" src="itemlink.js"></script></body></html>